package cn.lili.common.exception;

import cn.lili.common.enums.ResultCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;


/**
 * 全局业务异常类
 *
 * @author Chopper
 */
@Data
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 3447728300174142127L;
    /**
     * 异常消息
     */
    private String msg;

    /**
     * 错误码
     */
    private ResultCode resultCode;

    public ServiceException(String msg) {
        this.resultCode = ResultCode.ERROR;
        this.msg = msg;
    }

    public ServiceException() {
        this.resultCode = ResultCode.ERROR;
        this.msg = resultCode.message();
    }

    public ServiceException(ResultCode resultCode) {
        this.resultCode = resultCode;
        this.msg = resultCode.message();
    }

    public ServiceException(ResultCode resultCode, String message) {
        this.resultCode = resultCode;
        this.msg = message;
    }

    public ServiceException(String message, Throwable e) {
        super(message, e);
        this.msg = message;
    }
}
